package com.zzy.mccjt.gateway.common.filter.privacy;

import com.zzy.mccjt.gateway.common.properties.PrivacyHandleProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author likejie
 * @version 1.0
 * @description: 隐私数据处理-->> 加密
 * @date 2019/8/28 20:01
 */
@Slf4j
@Service("privacyEncryptionHandle")
public class PrivacyEncryptionHandle /*extends AbstractPrivacyHandle*/ {


   /* @Override
    public PrivacyHandleProperties.HandleTarget needFilter(HashMap<String, PrivacyHandleProperties.HandleTarget> targets, List<PrivacyHandleProperties.HandleTarget> pers, String uri) {
        if(null != targets && targets.size() > 0){
            //固定匹配
            if (null != targets.get(uri)) {
                PrivacyHandleProperties.HandleTarget handleTarget = targets.get(uri);
                //出参output 加密
                if (null != handleTarget.getOutput() && handleTarget.getOutput().size() > 0) {
                    return handleTarget;
                }
            }
        }
        if(null != pers && pers.size() > 0) {
            //前缀匹配
            for(PrivacyHandleProperties.HandleTarget handleTarget : pers){
                if(!StringUtils.isEmpty(handleTarget.getUri())
                        && uri.startsWith(handleTarget.getUri())
                        && null != handleTarget.getOutput()
                        && handleTarget.getOutput().size() > 0){
                    return handleTarget;
                }
            }
        }
        return null;
    }
    @Override
    public HashMap<String, String> paramReady(HashMap<String, String> params, PrivacyHandleProperties.HandleTarget target, String key, Object o, JSONObject jo) {
        //拿到出参待加密属性配置
        HashMap<String, String> outConfMap = target.getOutput();
        //批量准备待加密参数 格式如下-> key：待加密属性  value：对应属性明文,加密级别模板id (英文逗号分割)
        if (!StringUtils.isEmpty(outConfMap.get(key))) {
            log.info("-------->加密属性：" + key + "=" + o.toString());
            //key：待加密属性  value：对应属性明文,加密级别模板no (英文逗号分割)
            if(!StringUtils.isEmpty(o.toString())){
                params.put(key, o.toString() + "," + outConfMap.get(key));
            }
        }
        return params;
    }
    @Override
    public void handle(JSONObject joAdd, HashMap<String, String> params) {
        log.debug("-------->发起加密");
        //调用加密服务 批量加密 目前为同子树同阶层属性的批量
        *//*if (null != params && params.size() > 0) {
            MapReqDTO dto = new MapReqDTO();
            dto.setParams(params);
            try {
                WebApiResponse<Map<String, String>> response = privacyHandleInterface.batchEnc(dto);
                if (response.isSuccess()) {
                    Map<String, String> map = response.getData();
                    joAdd.putAll(map);
                    log.debug("-------->加密成功: {}" ,map.toString());
                } else {
                    log.error("-------->加密失败: {}" ,response.getMessage());
                }
            } catch (FeignException e) {
                log.error(e.getMessage(), e);
                throw new BusinessException(SystemError.PRIVACY_DEC_ERROR.getCode(), "加密异常" + e.getMessage());
            }
        }*//*
    }*/

}
